package com.captain.special.二叉树.简单;

import com.captain.leetcode.TreeNode;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/5/6 15:52
 */
public class 相同的树100 {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        return recur(p, q);
    }

    public boolean recur(TreeNode p, TreeNode q) {
        //前序遍历,对值进行处理
        if (p == null && q == null) {
            return true;
        }
        if (p == null || q == null) {
            return false;
        }
        if (p.val != q.val) {
            return false;
        }
        boolean left = recur(p.left, q.left);
        boolean right = recur(p.right, q.right);
        return left && right;
    }

}
